/**
 * 
 */
package unifor.filetransfer.receptor;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.security.NoSuchAlgorithmException;

import jonelo.jacksum.JacksumAPI;
import jonelo.jacksum.algorithm.AbstractChecksum;

import unifor.filetransfer.Principal;
import unifor.filetransfer.exception.SegmentoInvalido;
import unifor.filetransfer.util.CabecalhoPdu;
import unifor.filetransfer.util.ProtocoloUtil;
import unifor.filetransfer.util.RecepcaoUtil;

/**
 * @author landim
 * 
 */
public class ReceptorTransmissorThread extends Thread {

	BufferedInputStream in = null;
	byte[] arquivo = null;
	byte[] cabecalho = null;
	CabecalhoPdu cabecalhoPdu = null;
    AbstractChecksum crc = null;

	

	public ReceptorTransmissorThread(BufferedInputStream in) {
		setPriority(Thread.MIN_PRIORITY);
		this.in = in;
	}

	public void run() {

		try {
			byte[] bytesLidos = null;
			int disponiveis = 0;
			
			while (in.available() == 0);
			
			Principal.log("Recebendo pacote de resposta");
			if ((disponiveis = in.available()) == 2 ) {
				bytesLidos = new byte[disponiveis];
				in.read(bytesLidos, 0, disponiveis);
				
				
				cabecalho = RecepcaoUtil.pegarCabecalho(bytesLidos, true);
				cabecalhoPdu = RecepcaoUtil.pegarCabecalhoPdu(cabecalho, true);
				
				//PDU de Resposta
				Principal.log("Recebeu resposta de OK");
					
			}
			
			
		} catch (Exception e) {
			e.printStackTrace();
			Principal.log(e.getMessage());
		}
		System.out.println("final da thread de receptor t");
		
	}
	
}
